package com.itheima.controller;

import com.itheima.pojo.NursingPage;
import com.itheima.pojo.NursingPageResult;
import com.itheima.pojo.NursingProject;
import com.itheima.pojo.Result;
import com.itheima.service.NursingProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/server")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询数据
     * @param nusingPage
     * @return
     */
    @GetMapping()
    public Result page( NursingPage nusingPage){
        NursingPageResult npr = nursingProjectService.page(nusingPage);
        return Result.success(npr);
    }

    /**
     * 新增数据
     * @param np
     * @return
     */
    @PostMapping
    public Result add(@RequestBody NursingProject np){
         nursingProjectService.add(np);

         return Result.success();
    }

    /**
     * 删除数据
     */
    //@DeleteMapping("/{id}")
    //这个是   /server？id=1
    @DeleteMapping()
    public Result delete(@RequestParam List<Integer> ids){
        nursingProjectService.delete(ids);
        return Result.success();
    }

    /**
     * 修改数据第一步回显
     */
    //这个是 /server/1
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id){
        NursingProject np =nursingProjectService.getById(id);
        return Result.success(np);
    }
    /**
     * 修改数据第二步删除操作
     */
    @PutMapping()
    public Result update(@RequestBody NursingProject np){
        nursingProjectService.update(np);
        return Result.success();
    }
}
